<template>
  <div>
    <div>A组件 : {{ count }}</div>
    <div><button @click="add">add</button></div>
    <div><button @click="sub">sub</button></div>

    <B @add="add" />
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
import { INCREMENT } from '@/store/mutationTypes';
import B from '@/components/B.vue';

export default {
  components: { B },
  created() {
    // $store是vuex的存储状态的地方
  },
  methods: {
    ...mapMutations({
      increment1: INCREMENT,
    }),
    add() {
      // this.$emit('add');
      // this.$store.commit('INCREMENT', { num: 3 });
      this.increment({ num: 3 });
    },
    sub() {
      this.$store.commit('decrement');
    },
  },
  computed: {
    ...mapState({
      count: (state) => state.count,
    }),
  },
};
</script>

<style>
</style>
